package servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.SistemaCVR;
import xml.SerializadorCotizacion;
import xml.XmlUtil;

import bean.vo.CotizacionVO;

/**
 * Servlet implementation class CotizarSolPendientes
 */
public class CotizarSolPendientes extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CotizarSolPendientes() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		try {
			List<CotizacionVO> cotizaciones = SistemaCVR.cotizarSolicitudesPendientes();
			
			if(cotizaciones.isEmpty()){
				session.setAttribute("mensaje", "No se encontraron cotizaciones a procesar");
				session.setAttribute("cotiz", new ArrayList<CotizacionVO>());
			}else{
				session.setAttribute("cotiz", cotizaciones);
				session.setAttribute("mensaje", "");
			}
		} catch (Exception e) {
			session.setAttribute("mensaje", "Se produjo un error al procesar las cotizaciones pendientes");
		}finally{
			RequestDispatcher dispatcher = request.getRequestDispatcher("/resultadoCotizarSolicitudes.jsp");
			dispatcher.forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
